package com.cn.onetrip.untility;

/**
 * MD5 ???�?2010-11-25
 * 
 * @author zhiyong.jing
 */
public class MD5 {

	public static String getMD5(String instr) {
		String s = null;
		// ?��?�????��?��? 16 �??表示???�?
		char hexDigits[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
				'a', 'b', 'c', 'd', 'e', 'f' };
		try {
			java.security.MessageDigest md = java.security.MessageDigest
					.getInstance("MD5");
			md.update(instr.getBytes());
			byte tmp[] = md.digest(); // MD5 ???�?????�?�� 128 �???��??��?
										// ?��???��示就??16 �????
			char str[] = new char[16 * 2]; // �?���????16 �??表示???�?��?�两�??�??
											// ??��表示??16 �????? 32 �??�?
			int k = 0; // 表示�??�??�??�??�??�?��
			for (int i = 0; i < 16; i++) { // �??�?���??�??�?? MD5 ???�?���??
											// �????16 �??�????��??
				byte byte0 = tmp[i]; // ??? i �????
				str[k++] = hexDigits[byte0 >>> 4 & 0xf]; // ?????���?4 �???��?�??,
															// >>>
															// 为�?�??移�?�???��?�?��?�移
				str[k++] = hexDigits[byte0 & 0xf]; // ?????���?4 �???��?�??
			}
			s = new String(str).toUpperCase(); // ?��??????��??���??�?

		} catch (Exception e) {

		}
		return s;
	}

}
